package com.wanpinghui.supplier.object.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wanpinghui.supplier.R;
import com.wanpinghui.wphlibrary.model.object.bean.FilterData;

import java.util.List;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/11/24
 ***/

public class ObjectFilterAdapter extends BaseAdapter {
    private Context context;
    private List<FilterData> datas;
    private SettingListener listener;

    public void setListener(SettingListener listener) {
        this.listener = listener;
    }

    public ObjectFilterAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<FilterData> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_lv_object_filter, null);
        final FilterData data = datas.get(position);
        TextView textView = (TextView) view.findViewById(R.id.tv_name);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_setting);
        textView.setText(data.getName());
        if (data.getType() == FilterData.TYPE_ARROW) {
            imageView.setVisibility(View.VISIBLE);
            imageView.setImageResource(R.mipmap.common_icon_arrow);
        } else if (data.getType() == FilterData.TYPE_SETTING) {
            imageView.setVisibility(View.VISIBLE);
            imageView.setImageResource(R.mipmap.discover_icon_set);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        int type=0;
                        if(data.getName().equals("我关注的区域"))
                            type=0;
                        if(data.getName().equals("我关注的类型"))
                            type=1;
                        listener.goSetting(type);
                    }
                }
            });
        } else {
            imageView.setVisibility(View.GONE);
        }
        return view;
    }

    public interface SettingListener {
        void goSetting(int type);
    }
}
